package zhouyang;

import java.util.concurrent.CountDownLatch;

/**
 * juc辅助类CountDownLatch()倒计数，做减法
 */
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        for (int i = 1; i <=6; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"\t离开教室");
            },String.valueOf(i)).start();
        }
        System.out.println(Thread.currentThread().getName()+"\t班长关门走人");
        Thread.sleep(2000);
        System.out.println("分隔线上是出问题的演示——————————————————————————————");
   CountDownLatch countDownLatch= new CountDownLatch(6);
        for (int i = 1; i <=6; i++) {
            new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"\t离开教室");
        countDownLatch.countDown();

            },String.valueOf(i)).start();
        }
        countDownLatch.await();
        System.out.println(Thread.currentThread().getName()+"\t班长关门离开教室");
    }
}
